package cn.lystudio.rohmtimeopwide_background_v11.mapper;

import cn.lystudio.rohmtimeopwide_background_v11.entity.po.MachinePO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MachinePOMapper extends BaseMapper<MachinePO> {
    @Select("SELECT *  " +
            "FROM t_machine_new  " +
            "WHERE 1=1 " +
            "AND machineNo=#{machineNo} " +
            "ORDER BY machineID DESC  " +
            "LIMIT 1  ")
    MachinePO get1NoCondition(MachinePO machinePO);

    @Update("UPDATE t_machine_new   " +
            "SET  machineNo=#{machineNo},machineName=#{machineName},enabled=#{enabled},deleted=#{deleted}   " +
            "WHERE machineNo=#{machineNo}")
    int uptMachineNoCondition(MachinePO machinePO);

    @Select("SELECT machine.*\n" +
            "FROM t_machine_new machine\n" +
            "INNER JOIN t_departments secDept ON secDept.departmentID=machine.secDeptID\n" +
            "INNER JOIN t_departments topDept ON secDept.parentID=topDept.departmentID\n" +
            "WHERE 1=1 \n" +
            "AND machine.enabled=1 AND machine.deleted=0 \n" +
            "AND secDept.enabled=1 AND secDept.deleted=0 \n" +
            "AND topDept.enabled=1 and topDept.deleted=0\n" +
            "AND machine.machineNO = #{machineNo}")
    MachinePO get1ByMachineNo_Usable(@Param("machineNo") String machineNo);
}
